// Copyright (C) 2020 Toitware ApS.
// Use of this source code is governed by a Zero-Clause BSD license that can
// be found in the tests/LICENSE file.

import expect show *

import crypto.aes show *

main:
  key := "01234567890123456789012345678901".to-byte-array
  iv := "abcdefghijklmnop".to-byte-array
  plaintext := "Now is the time for all good men to come to the aid of the party"

  enc := AesCbc.encryptor key iv
  dec := AesCbc.decryptor key iv

  encrypted := enc.encrypt plaintext.to-byte-array
  decrypted := dec.decrypt encrypted

  EXPECTED ::= [0x0C, 0x30, 0x6F, 0x1F, 0x95, 0xF1, 0x9C, 0x5B, 0xED, 0x6E,
      0xFB, 0x15, 0xF8, 0xCB, 0xA7, 0x51, 0x44, 0x64, 0x4B, 0xF4, 0x9C, 0x56, 0xD2,
      0xD2, 0xD7, 0x5F, 0xEF, 0x70, 0xCD, 0x76, 0x2D, 0x6C, 0x88, 0xA7, 0x28, 0x99,
      0x93, 0x40, 0x55, 0xD2, 0x45, 0x90, 0xDF, 0x69, 0xF3, 0x7E, 0xD5, 0xA4, 0x38,
      0xE8, 0x57, 0x14, 0xCE, 0x52, 0x9E, 0x4D, 0x88, 0x86, 0x3F, 0x5D, 0x1F, 0x67,
      0x72, 0x1F, 0x15, 0xDC, 0x46, 0x9A, 0x0A, 0xC1, 0x76, 0xFD, 0x39, 0xA1, 0x9D,
      0xFB, 0x3B, 0x53, 0xE0, 0xFA]

  expect encrypted == (ByteArray 64: EXPECTED[it])
  expect decrypted.to-string == plaintext
